﻿using SHRIS.MIS.Common.Model;
using SHRIS.MIS.Common.Util.Extension;
using SHRIS.MIS.Common.Util.Model;
using SHRIS.MIS.Entity.SystemManage;
using SHRIS.MIS.IService.SystemManage;
using SHRIS.MIS.Model.Param.SystemManage;
using SHRIS.MIS.Service.SystemManage;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SHRIS.MIS.Business.SystemManage
{
    public class PositionBLL
    {
        private IPositionService _positionService;

        public PositionBLL(IPositionService positionService)
        {
            _positionService = positionService;
        }

        #region 获取数据
        public async Task<TEntity<List<PositionEntity>>> GetList(PositionListParam param)
        {
            TEntity<List<PositionEntity>> obj = new TEntity<List<PositionEntity>>();
            obj.Data = await _positionService.GetList(param);
            obj.Tag = 1;
            return obj;
        }

        public async Task<TEntity<List<PositionEntity>>> GetPageList(PositionListParam param, Pagination pagination)
        {
            TEntity<List<PositionEntity>> obj = new TEntity<List<PositionEntity>>();
            obj.Data = await _positionService.GetPageList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TEntity<PositionEntity>> GetEntity(Guid id)
        {
            TEntity<PositionEntity> obj = new TEntity<PositionEntity>();
            obj.Data = await _positionService.GetEntity(id);
            obj.Tag = 1;
            return obj;
        }

        public async Task<TEntity<int>> GetMaxSort()
        {
            TEntity<int> obj = new TEntity<int>();
            obj.Data = await _positionService.GetMaxSort();
            obj.Tag = 1;
            return obj;
        }
        #endregion

        #region 提交数据
        public async Task<TEntity<string>> SaveForm(PositionEntity entity)
        {
            TEntity<string> obj = new TEntity<string>();
            if (_positionService.ExistPositionName(entity))
            {
                obj.Message = "职位名称已经存在！";
                return obj;
            }
            await _positionService.SaveForm(entity);
            obj.Data = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }

        public async Task<TEntity> DeleteForm(string ids)
        {
            TEntity obj = new TEntity();
            await _positionService.DeleteForm(ids);
            obj.Tag = 1;
            return obj;
        }
        #endregion
    }
}
